#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;

int maximalSquare(vector<vector<int>> &matrix)
{
    int m = matrix.size();
    int n = matrix[0].size();
    int Max = 0;
    vector<vector<int>> dp(m + 1, vector<int>(n + 1, 0));
    for (int i = 1; i <= m; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            if (matrix[i - 1][j - 1] == 1)
                dp[i][j] = min(dp[i - 1][j - 1], min(dp[i][j - 1], dp[i - 1][j])) + 1;
            Max = max(Max, dp[i][j]);
        }
    }
    return Max;
}

int main()
{
    vector<vector<int>> gird{{1, 0, 1, 0, 0}, {1, 0, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 0, 0, 1, 0}};
    cout << maximalSquare(gird) << endl;
    return 0;
}